package advancedpart.assignmentA3;

import static org.junit.Assert.*;

import java.io.IOException;
import java.util.HashMap;

import org.junit.Test;

import shared.SearchOperator;
import shared.WordElement;

public class SearcherA3Test {	
	//Variables for testing
	private HashMap<String, WordElement> wordMap = new HashMap<String, WordElement>();

	String dataSetA = "data/test/dataSetA.txt";		
	String dataSetB = "data/test/dataSetB.txt";		
	String dataSetC = "data/test/dataSetC.txt";		
	String dataSetD = "data/test/dataSetD.txt";
	String dataSetE = "data/test/dataSetE.txt";		
	String dataSetF = "data/test/dataSetF.txt";
	
	/*Test of getUrls*/
	private SearchOperator andOperator = SearchOperator.AND;
	private SearchOperator orOperator = SearchOperator.OR;
	
	/*
	 * Test of getUrls
	 */
	@Test
	public void testGetUrlsA() throws IOException {		
		
		assertEquals("[1]", SearcherA3.getUrls(SearcherA3.createWordMap(dataSetF), "bases", "are", andOperator));

	}
	
	@Test
	public void testGetUrlsB() throws IOException {
		
		assertEquals("[2, 1]", SearcherA3.getUrls(SearcherA3.createWordMap(dataSetF), "bases", "are", orOperator));

	}
	
	@Test
	public void testGetUrlsC() throws IOException {
		
		assertEquals("[]", SearcherA3.getUrls(SearcherA3.createWordMap(dataSetF), "spacecow", "bases", andOperator));

	}
	
	@Test
	public void testGetUrlsD() throws IOException {
		
		assertEquals("[2, 1]", SearcherA3.getUrls(SearcherA3.createWordMap(dataSetF), "bases", "spacecow", orOperator));

	}

	/*
	 * Test of createWordMap
	 */
	
	@Test
	public void testCreateWordMapA () throws IOException {
		wordMap.clear();
		
		assertEquals(wordMap, SearcherA3.createWordMap(dataSetA));
	}
	
	@Test
	public void testCreateWordMapB () throws IOException {
		wordMap.clear();
		
		assertEquals(wordMap, SearcherA3.createWordMap(dataSetB));
	}
	
	@Test
	public void testCreateWordMapC () throws IOException {
		wordMap.clear();
		
		WordElement your = new WordElement("your");
		your.addUrl("1");
		wordMap.put("your", your);
		
		assertEquals(wordMap, SearcherA3.createWordMap(dataSetC));
	}
	
	@Test
	public void testCreateWordMapD () throws IOException {
		wordMap.clear();
		
		WordElement your = new WordElement("your");
		your.addUrl("1");
		wordMap.put("your", your);
		
		WordElement bases = new WordElement("bases");
		bases.addUrl("1");
		wordMap.put("bases", bases);
		
		WordElement are = new WordElement("are");
		are.addUrl("1");
		wordMap.put("are", are);
		
		WordElement belong = new WordElement("belong");
		belong.addUrl("1");
		wordMap.put("belong", belong);
		
		WordElement to = new WordElement("to");
		to.addUrl("1");
		wordMap.put("to", to);
		
		WordElement us = new WordElement("us");
		us.addUrl("1");
		wordMap.put("us", us);
		
		assertEquals(wordMap, SearcherA3.createWordMap(dataSetD));
	}
	
	@Test
	public void testCreateWordMapE () throws IOException {
		wordMap.clear();
		
		WordElement your = new WordElement("your");
		your.addUrl("1");
		wordMap.put("your", your);
		
		assertEquals(wordMap, SearcherA3.createWordMap(dataSetE));
	}
	
	@Test
	public void testCreateWordMapF () throws IOException {
		wordMap.clear();
		
		WordElement your = new WordElement("your");
		your.addUrl("1");
		your.addUrl("2");
		wordMap.put("your", your);
		
		WordElement bases = new WordElement("bases");
		bases.addUrl("1");
		bases.addUrl("2");
		wordMap.put("bases", bases);
		
		WordElement are = new WordElement("are");
		are.addUrl("1");
		wordMap.put("are", are);
		
		WordElement belong = new WordElement("belong");
		belong.addUrl("1");
		wordMap.put("belong", belong);
		
		WordElement to = new WordElement("to");
		to.addUrl("1");
		wordMap.put("to", to);
		
		WordElement us = new WordElement("us");
		us.addUrl("1");
		wordMap.put("us", us);
		
		assertEquals(wordMap, SearcherA3.createWordMap(dataSetF));
	}
}
